<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
    <style>

         .out{
           width: 800px;
           height: 500px;
           margin: 50px auto;

         }
      .qq_div{
         width: 310px;
         height: 500 ;
         float: left;
         border:1px #ccc solid;
         margin-left: 60px;
         border-radius: 3px;
      }
      .qq_name{
        text-align: center;
        height: 40px;
        line-height: 40px;
        background-color:#50C0F6;
        color:#fff;
      }
      .qq_left_content,.qq_right_content{

         height: 400px;
         border-bottom: 1px #ccc solid;

      }
    .qq_left_footer,.qq_right_footer{
      text-align: center;
      line-height: 60px;
    }

    </style>
</head>
<body>
<div class='out'>
  <div class='qq_div'>
       <div class='qq_name'>张三</div>
        <div class='qq_left_content' id='qq_left_content'></div>
        <div class='qq_left_footer'>
            <input type="text" id='left_input'>
            <button type='button' id='left_send' >发送</button>
            <button type='button' id='left_update'>修改</button>
            <button type='button' id='left_delete'>撤回</button>
        </div>
  </div>
  <div class='qq_div'>
    <div class='qq_name'>李四</div>
    <div class='qq_right_content' id='qq_right_content'></div>
    <div class='qq_right_footer'>
      <input type="text" id='right_input'>
      <button type='button' id='right_send' >发送</button>
      <button type='button' id='right_update' >修改</button>
      <button type='button' id='right_delete' >撤回</button>
    </div>
</div>
</body>
</html>
<script src='./lib/jquery.min.js'></script>
<script>
  $(()=>{
    //--左边----------------------------------
    //给发送按钮绑定点击事件
    $("#left_send").click(()=>{
      //判断输入框是否有内容
      //获得输入框的值
      let val = $("#left_input").val();
      if(val!==""){
      //往左右两个显示框添加节点
      let leftpObj = $(`<p>${val}</p>`);
      leftpObj.css({'color':"green","text-align":"right"});
      //给说说的话添加一个标识符
      leftpObj.addClass("zhangsan");
      $('#qq_left_content').append(leftpObj);
      //右边
      let rightpObj = $(`<p>张三说:${val}</p>`);
      rightpObj.addClass("zhangsan");
      $('#qq_right_content').append(rightpObj);
      $("#left_input").val(""); 
    }else{
        alert("请输入内容！");
      }
    })

    //左边的修改
     $("#left_update").click(()=>{
        let val = $("#left_input").val();
        if(val==""){
          let leftpObj=$(`<p>${val}</p>`);
          leftpObj.addClass("zhangsan");
          leftpObj.css({'color':"green","text-align":"right"})
          $("#qq_left_content").find(".zhangsan").last().replaceWith(leftpObj);
          let rightObj=$(`<p>张三说:${val}</p>`);
          rightObj.addClass("zhangsan");
          $('#qq_right_content').find(".zhangsan").last().replaceWith(rightObj);
        }else{
          alert("请输入内容");
        }
     });

     //撤回
     $("#left_delete").click(()=>{
       //找到左边张三说的左后一个p元素
       $("#qq_left_content").find(".zhangsan").last().remove();
       $("#qq_right_content").find(".zhangsan").last().remove();

     });

    //-右边-------------------------------

    $("#right_send").click(()=>{
      //判断输入框是否有内容
      //获得输入框的值
      let val = $("#right_input").val();
      if(val!==""){
      //往左右两个显示框添加节点
      let rightpObj = $(`<p>${val}</p>`);
      rightpObj.css({'color':"green","text-align":"right"})
      $('#qq_right_content').append(rightpObj);
      //右边
      let leftpObj = $(`<p>李四说:${val}</p>`);
      $('#qq_left_content').append(leftpObj);
      $("#right_input").val("");
      }else{
        alert("请输入内容！");
      }
    })


  });


</script>

